import Router from 'koa-router'
import fs from 'fs'
console.log('__dirname', __dirname)
const fileList = fs.readdirSync(__dirname).filter(file => file !== 'allRoute.ts')

const router = new Router()
for (const file of fileList) {
  if (file.endsWith('ts')) {
    // 动态加载每一个文件
    /* eslint-disable-next-line */
    const routeFile = require(`./${file}`).default
    router.use(`/${file.replace(/\.ts/, '')}`, routeFile.routes(), routeFile.allowedMethods())
  }
}

export default router
